package org.gws.alaska.test;

import static org.junit.Assert.*;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipselabs.mongo.IMongoProvider;
import org.eclipselabs.mongo.emf.ext.IResourceSetFactory;
import org.eclipselabs.mongo.impl.MongoProvider;
import org.eclipselabs.mongo.emf.ext.impl.MongoResourceSetFactory;
import org.junit.Test;


/**
 * Test di integrazione con Apache Felix e MongoEMF 
 *
 */

class MongoDBTest {

	def Model model;
	def IResourceSetFactory rFactory;
	def Package p;

	@Test
	void buildModel() {

		model = UMLFactory.eINSTANCE.createModel();

		assert model != null;

		model.setName("TestUmlModel");
		p = model.createNestedPackage("MyPackage");

		assert p != null;

		Class c =  p.createOwnedClass("name", false);
		c.setName("TestClass");

		assert c != null;
	}

	@Test
	void testConnection() {

		MongoProvider provider = new MongoProvider();
		Dictionary<String, Object> properties = new Hashtable<String, Object>();
		properties.put(IMongoProvider.PROP_URI, "mongodb://localhost");

		IResourceSetFactory rFactory = new MongoResourceSetFactory();
		ResourceSet rSet =  rFactory.createResourceSet();
		Resource r = rSet.createResource(URI.createURI("mongodb://localhost:27017/test/"))

		assert r != null;

		r.getContents().add(model);
		r.getContents().add(p);

		try{
			r.save(null);
		}catch(IOException ioe){
			println ioe.toString();
		}
	}
}
